package com.dianxin.smartpark.web.attendance;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.alibaba.excel.EasyExcel;
import com.chinatelecom.response.common.CommonResponseBody;
import com.chinatelecom.response.utils.ResponseBodyWrapperUtil;
import com.chinatelecom.response.utils.StringUtils;
import com.dianxin.smartpark.dao.dataobject.attendance.SmartParkAttendanceStatistics;
import com.dianxin.smartpark.dao.qo.attendance.SmartParkAttendanceStatisticsQO;
import com.dianxin.smartpark.service.attendance.SmartParkAttendanceStatisticsService;
import com.dianxin.sso.client.annotation.RecordLog;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.awt.*;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/** 考勤统计
 * @program: smart-park
 * @description: 考勤统计
 * @author: chenyong
 * @create: 2021-09-01 19:40
 */
@RestController
@RequestMapping("/smartpark/attendance/attendanceStatistics")
public class SmartParkAttendanceStatisticsController {

    @Resource
    private SmartParkAttendanceStatisticsService smartParkAttendanceStatisticsService;

    /**
     * 考勤月报
     * @Description:  考勤月报
     * @Author: ChenYong
     * @Date: 2021/9/1 0001
     * @param smartParkAttendanceStatistics:
     * @Return: List<SmartParkAttendanceStatistics>
     */
    @PostMapping("/selectByMonth")
    @RecordLog(name = "考勤月报")
    @SaCheckPermission("/attendance/attendanceStatistics/selectByMonth")
    public CommonResponseBody<List<SmartParkAttendanceStatistics>> selectByMonth(@RequestBody SmartParkAttendanceStatisticsQO smartParkAttendanceStatistics){
        return smartParkAttendanceStatisticsService.selectByMonth(smartParkAttendanceStatistics);
    };

    /**
     * 考勤日报
     * @Description:  考勤日报
     * @Author: ChenYong
     * @Date: 2021/9/1 0001
     * @param smartParkAttendanceStatistics:
     * @Return: List<SmartParkAttendanceStatistics>
     */
    @PostMapping("/selectByDay")
    @RecordLog(name = "考勤日报")
    @SaCheckPermission("/attendance/attendanceStatistics/selectByDay")
    public CommonResponseBody<List<SmartParkAttendanceStatistics>> selectByDay(@RequestBody SmartParkAttendanceStatisticsQO smartParkAttendanceStatistics){
        return smartParkAttendanceStatisticsService.selectByDay(smartParkAttendanceStatistics);
    };

    /**
     * 导出考勤日报表
     * @Description:  导出考勤日报表
     * @Author: ChenYong
     * @Date: 2021/9/1 0001
     * @param smartParkAttendanceStatistics:
     * @Return: CommonResponseBody<List<SmartParkAttendanceStatistics>>
     */
    @GetMapping("/exportByDay")
    @RecordLog(name = "导出考勤日报")
    @SaCheckPermission("/attendance/attendanceStatistics/exportByDay")
    public void exportByDay(SmartParkAttendanceStatisticsQO smartParkAttendanceStatistics, HttpServletResponse response) throws Exception{
        CommonResponseBody<List<SmartParkAttendanceStatistics>> listCommonResponseBody = smartParkAttendanceStatisticsService.selectByDay(smartParkAttendanceStatistics);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmm");
        String date = sdf.format(new Date());
        String fileName = "考勤日报表"+date + ".xlsx";
        response.setHeader("Content-Disposition", "attachment;filename="+fileName);
        EasyExcel.write(response.getOutputStream(), SmartParkAttendanceStatistics.class).sheet("模板").doWrite(listCommonResponseBody.getData());
    }



    /**
     * 导出考勤月报表
     * @Description:  导出考勤月报表
     * @Author: ChenYong
     * @Date: 2021/9/1 0001
     * @param smartParkAttendanceStatistics:
     * @Return: CommonResponseBody<List<SmartParkAttendanceStatistics>>
     */
    @GetMapping("/exportByMonth")
    @RecordLog(name = "导出考勤月报")
    @SaCheckPermission("/attendance/attendanceStatistics/exportByMonth")
    public void exportByMonth(SmartParkAttendanceStatisticsQO smartParkAttendanceStatistics, HttpServletResponse response) throws Exception{
        CommonResponseBody<List<SmartParkAttendanceStatistics>> listCommonResponseBody = smartParkAttendanceStatisticsService.selectByMonth(smartParkAttendanceStatistics);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmm");
        String date = sdf.format(new Date());
        String fileName = "考勤月报表"+date + ".xlsx";
        response.setHeader("Content-Disposition", "attachment;filename="+fileName);
        EasyExcel.write(response.getOutputStream(), SmartParkAttendanceStatistics.class).sheet("模板").doWrite(listCommonResponseBody.getData());
    }

    /**
     * 统计每月每天是否有异常数据
     * @Description:  统计每月每天是否有异常数据
     * @Author: ChenYong
     * @Date: 2021/9/2 0002
     * @param smartParkAttendanceStatistics:
     * @Return: CommonResponseBody<List<SmartParkAttendanceStatistics>>
     */
    @PostMapping("/selectByMonthAbnormal")
    @RecordLog(name = "统计每月每天是否有异常数据")
    @SaCheckPermission("/attendance/attendanceStatistics/selectByMonthAbnormal")
    public CommonResponseBody<List<SmartParkAttendanceStatistics>> selectByMonthAbnormal(@RequestBody SmartParkAttendanceStatistics smartParkAttendanceStatistics) {
        return smartParkAttendanceStatisticsService.selectByMonthAbnormal(smartParkAttendanceStatistics);
    }
}
